#include <iostream>#include <string>
#include <sstream>
#include <map>
#include <vector>
#include <algorithm>

std::map<std::string, std::string> number_names = {
    {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"},
    {"four", "4"}, {"five", "5"}, {"six", "6"}, {"seven", "7"},
    {"eight", "8"}, {"nine", "9"}
};

bool is_prime(int number) {
    if (number <= 1) return false;
    for (int i = 2; i < number; ++i) {
        if (number % i == 0) return false;
    }
    return true;
}

int main() {
    std::string user_input;
    std::getline(std::cin, user_input);
    std::istringstream input_stream(user_input);
    std::vector<std::string> words;
    std::string current_word;
    while (input_stream >> current_word) {
        words.push_back(current_word);
    }

    std::string number_string;
    try {
        for (const auto& word : words) {
            number_string += number_names.at(word);
        }
    }
    catch (const std::out_of_range&) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    int number = std::stoi(number_string);

    int smaller_prime = number;
    int larger_prime = number;

    while (!is_prime(smaller_prime)) {
        smaller_prime--;
    }

    while (!is_prime(larger_prime)) {
        larger_prime++;
    }

    if (number - smaller_prime < larger_prime - number) {
        std::cout << smaller_prime << std::endl;
    }
    else {
        std::cout << larger_prime << std::endl;
    }

    return 0;
}